package com.fudan.framework.web.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.fudan.framework.entity.RequestEntity;
import com.fudan.framework.entity.ResponseMsg;

/**
 * 删除的controller
 * @author Xuxinxing
 *
 * @param <T>
 */
public interface DeleteController<T extends RequestEntity> extends FunctionalController<T>{
    @RequestMapping("/delete")
    @ResponseBody
    default public ResponseMsg doDelete(HttpServletRequest request) {
        try {
            checkPermission("delete");
            Boolean result = delete(request);
            if (result) {
                return ResponseMsg.build(SUCCESS_CODE, SUCCESS);
            } else {
                return ResponseMsg.build(DELETE_ERROR_CODE, "删除失败");
            }
        } catch (Exception e) {
            return ResponseMsg.build(SYSTEM_ERROR_CODE, "删除失败");
        }
    }

    default public Boolean delete(HttpServletRequest request) {
        String id = request.getParameter("id");
        Boolean result = injectService().delete(id);
        return result;
    }
}
